<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <form class="layui-form">
                <div class="layui-form lay-header">
                    <div class="toolbar">
                        <div class="layui-form-item lay-query-content">
                            <div class="lay-query-box">
                                <div class="query-lt">
                                    <div class="layui-inline">
                                        <label class="layui-form-label w-auto">签收记录编号：</label>
                                        <div class="layui-input-inline mr0">
                                            <input name="code" class="layui-input" type="text" placeholder="签收记录编号"/>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label w-auto">配送单编号：</label>
                                        <div class="layui-input-inline mr0">
                                            <input name="deliveryOrderCode" class="layui-input" type="text" placeholder="配送单编号"/>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label w-auto">创建时间：</label>
                                        <div class="layui-input-inline">
                                            <input  id="pTime" class="layui-input date-icon" type="text" placeholder="选择创建时间" autocomplete="off" readonly/>
                                            <input name="startCreateTime" id="sTime" style="display: none"/>
                                            <input name="endCreateTime" id="eTime" style="display: none"/>
                                        </div>

                                    </div>
                                </div>
                                <div class="query-rt">
                                    <div class="layui-inline">
                                        <button class="layui-btn icon-btn" lay-filter="formSubSearchLog" lay-submit
                                                type="button">查询
                                        </button>
                                        <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit
                                                type="reset">
                                            重置
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            <!-- 表格 -->
            <table class="layui-table" id="cloudStorageWorkTable" lay-filter="cloudStorageWorkTable"></table>
        </div>
    </div>
</div>
<style>
    .companyFormClass .open-details-box{
        padding: 20px;
    }
    .companyFormClass .open-details-box input{
        border: none !important;
        color: #666;
    }
    .addPutGoodsInfoFrom table,
    .addPutMaterialsFrom table{
        margin: 0;
    }
</style>
<!-- 表格操作列 -->
<script type="text/html" id="cloudStorageWorkTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="putGoods">入库作业</a>
</script>

<!--添加入库信息表格操作-->
<script type="text/html" id="trayStoreGoodsListTableBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="addGoods">添加入库信息</a>
</script>

<script type="text/html" id="trayInfoTableBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="addGoods">添加入库信息</a>
</script>


<!--添加入库物资表格操作-->
<script type="text/html" id="addWorkGoodsTableBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="edit">修改</a>
</script>

<script type="text/html" id="workBinGoodsTableBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="add">添加入库</a>
</script>

<!--详情弹窗-->
<script type="text/html" id="cloudStorageWorkDetailForm">
    <form lay-filter="cloudStorageWorkDetailForm" class="layui-form model-form companyFormClass">
        <div class="open-details-box" style="height: 100%;">
            <div class="layui-row">
                <div class="open-details-title">签收单 </div>
                <table class="layui-table" id="signOrderDetailTable" lay-filter="signOrderDetailTable"></table>
            </div>
            <div class="layui-row">
                <div class="open-details-title">入库商品</div>
                <table class="layui-table" id="cloudStorageWorkDetailTable" lay-filter="cloudStorageWorkDetailTable"></table>
            </div>
        </div>
    </form>
</script>

<!-- 入库作业弹窗 -->
<script type="text/html" id="cloudStorageWorkModelForm">
    <form lay-filter="cloudStorageWorkModelForm" class="layui-form model-form">
        <div class="open-details-box">
            <div class="layui-row table-bor" style="padding-top: 20px;">
                <div class="open-details-title">签收订单信息</div>
                <table class="layui-table" id="workShowDetailTable" lay-filter="workShowDetailTable"></table>
            </div>
            <div class="layui-row" style="margin-top: 15px;">
                <div class="layui-col-md4 table-bor">
                    <div class="layui-form-item">
                        <div class="open-details-title">入库订单信息</div>
                    </div>
                    <table class="layui-table" id="signWorkDetailTable" lay-filter="signWorkDetailTable"></table>
                </div>
                <div class="layui-col-md8 table-bor" style="padding-left: 25px">
                    <div class="layui-form-item">
                        <div class="open-details-title">入库物资</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label w-auto">扫描料箱编码</label>
                        <div class="layui-input-inline" style="width: 260px;">
                            <input name="workBinCode" type="text" class="layui-input"/>
                        </div>
                        <div class="layui-input-inline">
                            <button class="layui-btn icon-btn color-green" id="scanWorkBinCode">确定</button>
                        </div>
                    </div>
                    <table class="layui-table" id="workBinGoodsTable" lay-filter="workBinGoodsTable"></table>
                    <div style="padding-top: 10px;">
                        <span class="red boxCode"></span>
                        <label>库存明细</label>
                    </div>
                    <table class="layui-table" id="workInventoryDetailTable" lay-filter="workInventoryDetailTable"></table>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>
</script>

<!--添加入库信息弹窗-->
<script type="text/html" id="addPutGoodsInfoFrom">
    <form lay-filter="addPutGoodsInfoFrom" class="layui-form model-form addPutGoodsInfoFrom" style="padding: 10px 20px">
        <div class="layui-row">
            <div class="open-details-title">托盘信息</div>
            <table class="layui-table" id="trayInfoTable" lay-filter="trayInfoTable"></table>
        </div>
        <div class="layui-row">
            <div class="open-details-title">托盘存放物资列表</div>
            <table class="layui-table" id="trayStoreGoodsListTable" lay-filter="trayStoreGoodsListTable"></table>
        </div>
    </form>
</script>

<!--添加入库物资弹窗-->
<script type="text/html" id="addPutMaterialsFrom">
    <form lay-filter="addPutMaterialsFrom" class="layui-form model-form addPutMaterialsFrom" style="padding: 10px 20px">
        <div class="open-details-box">
            <div class="layui-row">
                <div class="open-details-title">托盘信息</div>
                <table class="layui-table" id="detailTrayInfoTable" lay-filter="detailTrayInfoTable"></table>
            </div>
            <div class="layui-row">
                <div class="layui-form-item">
                    <div class="open-details-title">入库物资</div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label w-auto">扫描包装码</label>
                    <div class="layui-input-inline" style="width: 260px;">
                        <input name="detailWorkBinCode" type="text" class="layui-input"/>
                    </div>
                    <div class="layui-input-inline">
                        <button class="layui-btn icon-btn color-green" id="detailScanWorkBinCode">确定</button>
                    </div>
                </div>
                <table class="layui-table" id="addWorkGoodsTable" lay-filter="addWorkGoodsTable"></table>
            </div>
        </div>
        <div class="layui-form-item text-right" style="border-top: 1px solid #F0F2F5;padding-top: 20px;">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="addPutMaterialsFromSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!--物资弹窗里的添加入库信息-->
<script type="text/html" id="materialsAddPutFrom">
    <form lay-filter="materialsAddPutFrom" class="layui-form model-form addPutMaterialsFrom" style="padding: 20px;">
        <div class="open-details-box">
            <input type="hidden" name="productPic">
            <div class="layui-row">
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <div class="open-details-title">托盘信息</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">料箱编号</label>
                        <div class="layui-input-inline">
                            <input name="boxCode" type="text" class="layui-input red br0" readonly="readonly"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">扫描包装码</label>
                        <div class="layui-input-inline">
                            <input name="packLabelCode" type="text" class="layui-input label br0" readonly="readonly"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">签收数量</label>
                        <div class="layui-input-inline">
                            <input name="packLabelQuantity" type="text" class="layui-input red br0" readonly="readonly"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">入库数量</label>
                        <div class="layui-input-inline">
                            <input name="quantity" type="text" class="layui-input" required lay-filter="required"/>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md7 layui-col-md-offset1">
                    <div class="layui-form-item">
                        <div class="open-details-title">物料信息</div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">物料编号</label>
                                <div class="layui-input-inline">
                                    <input name="skuCode" type="text" class="layui-input label br0" readonly="readonly"/>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">物料名称</label>
                                <div class="layui-input-inline">
                                    <input name="skuName" type="text" class="layui-input label br0" readonly="readonly"/>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">品牌</label>
                                <div class="layui-input-inline">
                                    <input name="productBrandName" type="text" class="layui-input label br0" readonly="readonly"/>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">物料类型</label>
                                <div class="layui-input-inline">
                                    <input name="productTypeName" type="text" class="layui-input label br0" readonly="readonly"/>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">物料规格</label>
                                <div class="layui-input-inline">
                                    <input name="skuSpec" type="text" class="layui-input label br0" readonly="readonly"/>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">包装规格</label>
                                <div class="layui-input-inline">
                                    <input name="packName" type="text" class="layui-input label br0" readonly="readonly"/>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">物料图片</label>
                        <div class="layui-input-inline">
                            <img class="skuPic" src="" alt="" style="height: 60px; width: 120px;">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row" style="padding-top: 10px;">
                <div class="layui-form-item">
                    <div class="open-details-title">业务信息</div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">存入操作员</label>
                    <div class="layui-input-inline">
                        <input name="storagePeople" type="text" class="layui-input label br0" readonly="readonly"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">入库时间</label>
                    <div class="layui-input-inline">
                        <input name="storageTime" type="text" class="layui-input label br0" readonly="readonly"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">备注信息</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <textarea name="remark" class="layui-textarea" ></textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="auditFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var laydate = layui.laydate;
        var deliverProductArr = [];
        var signId = '';

        //时间范围
        laydate.render({
            elem: '#pTime',
            type: 'date',
            range: true,
            done: function(value, date, endDate){
                if (value){
                    let dateValue = value.split(" - ");
                    $("input[name='startCreateTime']").val(dateValue[0] + " 00:00:00");
                    $("input[name='endCreateTime']").val(dateValue[1] + " 23:59:59");
                }else {
                    $("input[name='startCreateTime']").val("");
                    $("input[name='endCreateTime']").val("");
                }
            }
        });

        // 渲染表格
        var insTb = table.render({
            elem: '#cloudStorageWorkTable',
            url: config.base + 'enterprisecab/order/admin/orderDeliverySignStorage/list',
            page: true,
            cellMinWidth: 120,
            cols: [[
                { field: 'number', title: '序号', width: 50, type: 'numbers' }
                ,{field: 'code', title: '签收记录编号', align: 'center', sort: true}
                ,{field: 'deliveryOrderCode', title: '配送单编号', align: 'center'}
                ,{field: 'cabNum', title: '柜子数量', align: 'center'}
                ,{field: 'skuNum', title: '物料数量', align: 'center'}
                ,{field: 'distributionClerk', title: '配货员', align: 'center'}
                ,{field: 'statusDesc', title: '状态', align: 'center'}
                ,{field: 'createTime', title: '创建时间', align: 'center', sort: true}
                ,{align: 'center', toolbar: '#cloudStorageWorkTableBar', title: '操作', width: 200}
            ]]
        });

        // 工具条点击事件
        table.on('tool(cloudStorageWorkTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') { //详情
                showDetailModel(data);
            } else if (obj.event === 'putGoods') { // 入库作业
                showEditModel(data);
            }
        });

        //监听排序
        table.on('sort(cloudStorageWorkTable)', function(obj){
            table.reload('cloudStorageWorkTable', {
                initSort: obj
                ,where: {
                    sort: obj.field
                    ,order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        //渲染下拉框
        form.render('select');

        // 显示详情弹窗
        function showDetailModel(data) {
            let signOrderDetailTableData = [];
            signOrderDetailTableData.push(data);
            admin.open({
                type: 1,
                isDetail: true,
                area: '1300px',
                offset: '65px',
                title: '云仓入库单详情',
                content: $('#cloudStorageWorkDetailForm').html(),
                success: function () {

                    var signOrderDetailTable = table.render({
                        elem: '#signOrderDetailTable',
                        data: signOrderDetailTableData,
                        cellMinWidth: 120,
                        cols: [[
                            {field: 'code', title: '签收记录编号', align: 'center'}
                            ,{field: 'deliveryOrderCode', title: '配送单编号', align: 'center'}
                            ,{field: 'cabNum', title: '柜子数量', align: 'center'}
                            ,{field: 'skuNum', title: '物料数量', align: 'center'}
                            ,{field: 'distributionClerk', title: '配货员', align: 'center'}
                            ,{field: 'statusDesc', title: '状态', align: 'center'}
                            ,{field: 'createTime', title: '创建时间', align: 'center', width: '160'}
                        ]]
                    });

                    var deliverProductTable = table.render({
                        elem: '#cloudStorageWorkDetailTable',
                        url: config.base + 'enterprisecab/order/admin/orderDeliverySignStorage/getSignStorageDetailList?signId=' + data.id,
                        page: true,
                        cellMinWidth: 120,
                        cols: [[
                            { field: 'number', title: '序号', width: 60, type: 'numbers' }
                            , { field: 'skuCode', sort: true, title: '物料编号'}
                            , { field: 'productName', sort: true, title: '物料名称'}
                            , { field: 'skuSpecValueNames', sort: true, title: '规格'}
                            , { field: 'unitName', title: '单位'}
                            , { field: 'quantityConfirm', title: '补货数量' }
                            , { field: 'quantityDistribute', title: '配送数' }
                            , { field: 'quantitySign', title: '签收数' }
                            , { field: 'statusDesc', title: '状态'}
                            , { field: 'quantityStorage', title: '入库数' }
                        ]]
                    });
                    //监听排序
                    table.on('sort(cloudStorageWorkDetailTable)', function(obj){
                        table.reload('cloudStorageWorkDetailTable', {
                            initSort: obj
                            ,where: {
                                sort: obj.field
                                ,order: obj.type
                            }
                        });
                    });
                }
            });
        }

        // 显示编辑弹窗
        function showEditModel(data) {
            let signStatusDetailTableData = [];
            signStatusDetailTableData.push(data);
            signId = data.id;
            admin.open({
                type: 1,
                isDetail: true,
                area: '1560px',
                offset: '65px',
                title: '云仓入库业务操作',
                content: $('#cloudStorageWorkModelForm').html(),
                success: function () {
                    // 物料明细ID
                    let deliveryDetailId = '';
                    // 物料料箱
                    let workBinData = [];
                    // 料箱下的物料
                    let boxData = [];
                    var insTb2 = table.render({
                        elem: '#workShowDetailTable',
                        data: signStatusDetailTableData,
                        cellMinWidth: 120,
                        cols: [[
                            {field: 'code', title: '签收记录编号', align: 'center'}
                            ,{field: 'deliveryOrderCode', title: '配送单编号', align: 'center'}
                            ,{field: 'cabNum', title: '柜子数量', align: 'center'}
                            ,{field: 'skuNum', title: '物料数量', align: 'center'}
                            ,{field: 'distributionClerk', title: '配货员', align: 'center'}
                            ,{field: 'statusDesc', title: '状态', align: 'center'}
                            ,{field: 'createTime', title: '创建时间', align: 'center', width: '160'}
                        ]]
                    });

                    // 查询入库商品信息
                    admin.req('enterprisecab/order/admin/orderDeliverySignStorage/getSignStorageDetailList', { signId: signId }, function (res) {
                        if (res.code == 200) {
                            deliverProductArr = res.data;
                            table.reload('signWorkDetailTable', {
                                data: deliverProductArr,
                            })
                        } else {
                            layer.msg(res.msg, { icon: 2 });
                        }
                    }, 'GET');

                    // 入库订单信息
                    var insTb3 = table.render({
                        elem: '#signWorkDetailTable',
                        data: deliverProductArr,
                        cellMinWidth: 100,
                        cols: [[
                            { field: 'number', title: '序号', width: 50, type: 'numbers' }
                            ,{field: 'skuCode', title: '物料编号', align: 'center'}
                            ,{field: 'productName', title: '物料名称', align: 'center'}
                            ,{field: 'quantityDistribute', title: '应收数', align: 'center'}
                            ,{field: 'quantitySign', title: '已签收数', align: 'center'}
                        ]]
                    });

                    table.on('row(signWorkDetailTable)', function (obj) {
                        deliveryDetailId = obj.data.deliveryDetailId
                        // 清空
                        table.reload('workInventoryDetailTable', {
                            data: [],
                        })
                        getWorkBinListByJobProductId(deliveryDetailId)
                    });

                    // 查询料箱
                    function getWorkBinListByJobProductId(deliveryDetailId) {
                        layer.load(2);
                        admin.req('enterprisecab/order/admin/orderDeliverySignStorage/getProductBoxByDetailId', { deliveryDetailId: deliveryDetailId }, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                workBinData = res.data;
                                table.reload('workBinGoodsTable', {
                                    data: workBinData,
                                })
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                    }

                    // workSignInAddGoods
                    // 料箱表格
                    var insTb4 = table.render({
                        elem: '#workBinGoodsTable',
                        data: workBinData,
                        cellMinWidth: 120,
                        cols: [[
                            { field: 'number', title: '序号', width: 50, type: 'numbers' }
                            ,{field: 'code', title: '料箱编号', align: 'center'}
                            ,{field: 'vehicleName', title: '料箱类型', align: 'center'}
                            ,{field: 'spaceCode', title: '所在货位', align: 'center'}
                            ,{field: 'warehouseCode', title: '所在仓库编号', align: 'center'}
                            ,{field: 'shelfName', title: '货架编号', align: 'center'}
                            ,{align: 'center', toolbar: '#workBinGoodsTableBar', title: '操作'}
                        ]]
                    });

                    // 料箱添加入库
                    table.on('tool(workBinGoodsTable)', function (obj) {
                        let data = obj.data;
                        if (obj.event === 'add') { // 添加
                            getWorkbinByCode(data.code);
                        }
                    });

                    // 料箱行点击事件
                    table.on('row(workBinGoodsTable)', function (obj) {
                        let boxId = obj.data.boxId;
                        let boxCode = obj.data.code;
                        getInventoryJobLabelVOByBoxId(boxId, boxCode)
                    });

                    // 查询料箱下的包装码
                    function getInventoryJobLabelVOByBoxId(boxId, boxCode) {
                        layer.load(2);
                        admin.req('enterprisecab/order/admin/orderDeliverySignStorage/getDeliveryLabelVOByBoxId', { boxId: boxId }, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                $(".boxCode").text(boxCode);
                                boxData = res.data;
                                boxData.forEach((item, index) => {
                                    boxData[index].boxCode = boxCode
                                })
                                table.reload('workInventoryDetailTable', {
                                    data: boxData,
                                })
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                    }

                    // 库存明细
                    var insTb5 = table.render({
                        elem: '#workInventoryDetailTable',
                        data: boxData,
                        cellMinWidth: 120,
                        cols: [[
                            { field: 'number', title: '序号', width: 50, type: 'numbers' }
                            ,{field: 'packLabelCode', title: '包装码', align: 'center'}
                            ,{field: 'skuCode', title: '物料编号', align: 'center'}
                            ,{field: 'packName', title: '包装规格', align: 'center'}
                            ,{field: 'packLabelQuantity', title: '签收数', align: 'center'}
                            ,{field: 'storageQuantity', title: '入库数', align: 'center'}
                            ,{field: 'boxCode', title: '料箱编号', align: 'center'}
                            ,{field: 'statusDesc', title: '状态', align: 'center'}
                            // ,{align: 'center', toolbar: '#workBinGoodsTableBar', title: '操作'}
                        ]]
                    });

                    // 料箱编码确定
                    $("#scanWorkBinCode").click(function() {
                        let workBinCode = $("input[name='workBinCode']").val();
                        if(workBinCode == '') {
                            layer.msg('请输入料箱编码', { icon: 2 });
                            return false;
                        }
                        getWorkbinByCode(workBinCode);
                        return false;
                    });

                    function getWorkbinByCode(workBinCode) {
                        // 查询料箱数据
                        layer.load(2);
                        admin.req('enterprisecab/order/admin/orderDeliverySignStorage/getWorkbinByCode', { code: workBinCode }, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                if(Object.keys(res.data).length > 0) {
                                    addPutGoodsInfoModel(res.data)
                                } else {
                                    layer.msg('料箱编码不存在', { icon: 2 });
                                }
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                    }
                }
            });
        }

        // 托盘存放物资列表//添加入库信息
        function addPutGoodsInfoModel(data) {
            let boxDetail = [];
            boxDetail.push(data);
            admin.open({
                type: 1,
                area: ['1300px', '868px'],
                offset: '56px',
                title: '托盘存放物资列表',
                content: $('#addPutGoodsInfoFrom').html(),
                success: function () {
                    var trayInfoTable = table.render({
                        elem: '#trayInfoTable',
                        data: boxDetail,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'code', title: '料箱编号', align: 'center'}
                            ,{field: 'vehicleName', title: '料箱类型', align: 'center'}
                            ,{field: 'materialsQuantity', title: '存放物资数量', align: 'center'}
                            ,{field: 'spaceCode', title: '货位', align: 'center'}
                            ,{field: 'warehouseName', title: '仓库名称', align: 'center'}
                            ,{field: 'areaName', title: '库区', align: 'center'}
                            ,{field: 'shelfName', title: '货架编号', align: 'center'}
                            ,{field: 'managerName', title: '仓库负责人', align: 'center'}
                            ,{align: 'center', toolbar: '#trayInfoTableBar', title: '操作'}
                        ]]
                    });

                    table.on('tool(trayInfoTable)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'addGoods') { //添加入库信息
                            addPutMaterialsModel(data);
                        }
                    });

                    // 托盘下的物资
                    var trayStoreGoodsListTable = table.render({
                        elem: '#trayStoreGoodsListTable',
                        url: config.base + 'enterprisecab/order/admin/orderDeliverySignStorage/getMaterialVOListById?boxId=' + data.boxId,
                        page: true,
                        cellMinWidth: 120,
                        cols: [[
                            { field: 'number', title: '序号', width: 50, type: 'numbers' }
                            ,{field: 'skuCode', title: '物资编号', align: 'center'}
                            ,{field: 'productName', title: '物资名称', align: 'center'}
                            ,{field: 'labelQuantity', title: '包装数量', align: 'center'}
                            ,{field: 'amountQuantity', title: '最小单位货位存数', align: 'center'}
                            // ,{align: 'center', toolbar: '#trayStoreGoodsListTableBar', title: '操作'}
                        ]]
                    });

                    table.on('tool(trayStoreGoodsListTable)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'addGoods') { //添加入库信息
                            addPutMaterialsModel(data);
                        }
                    });
                }
            });
        }

        // 添加入库物资信息
        function addPutMaterialsModel(data) {
            let boxId = data.boxId;
            let boxDetailData = [];
            boxDetailData.push(data);
            let addWorkGoodsList = [];
            var addPutMaterialsOpen = admin.open({
                type: 1,
                area: ['1260px', '868px'],
                offset: '56px',
                title: '添加入库物资信息',
                content: $('#addPutMaterialsFrom').html(),
                success: function () {
                    var detailTrayInfoTable = table.render({
                        elem: '#detailTrayInfoTable',
                        data: boxDetailData,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'code', title: '料箱编号', align: 'center'}
                            ,{field: 'vehicleName', title: '料箱类型', align: 'center'}
                            ,{field: 'materialsQuantity', title: '存放物资数量', align: 'center'}
                            ,{field: 'spaceCode', title: '货位', align: 'center'}
                            ,{field: 'warehouseName', title: '仓库名称', align: 'center'}
                            ,{field: 'areaName', title: '库区', align: 'center'}
                            ,{field: 'shelfName', title: '货架编号', align: 'center'}
                            ,{field: 'managerName', title: '仓库负责人', align: 'center'}
                        ]]
                    });

                    // 扫描包装码
                    $("#detailScanWorkBinCode").click(function() {
                        let code = $("input[name='detailWorkBinCode']").val();
                        if(code == '') {
                            layer.msg('请输入包装码', { icon: 2 });
                            return false;
                        }
                        getInventoryJobLabelByCode(code, boxId);
                        return false;
                    })

                    // 查询条码
                    function getInventoryJobLabelByCode(code) {
                        layer.load(2);
                        admin.req('enterprisecab/order/admin/orderDeliverySignStorage/getDeliveryLabelVOByCode', { packLabelCode: code, signId: signId}, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                materialsEditModel(res.data, data.code, boxId);
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                    }

                    var addWorkGoodsTable = table.render({
                        elem: '#addWorkGoodsTable',
                        data: addWorkGoodsList,
                        cellMinWidth: 120,
                        cols: [[
                            { field: 'number', title: '序号', width: 50, type: 'numbers' }
                            ,{field: 'packLabelCode', title: '包装码', align: 'center'}
                            ,{field: 'skuCode', title: '物料编号', align: 'center'}
                            ,{field: 'packName', title: '包装规格', align: 'center'}
                            ,{field: 'packLabelQuantity', title: '签收数', align: 'center'}
                            ,{field: 'quantity', title: '入库数', align: 'center'}
                            ,{field: 'remark', title: '备注信息', align: 'center'}
                            ,{field: 'statusDesc', title: '状态', align: 'center'}
                            ,{align: 'center', toolbar: '#addWorkGoodsTableBar', title: '操作'}
                        ]]
                    });

                    table.on('tool(addWorkGoodsTable)', function (obj) {
                        let goods = obj.data;
                        if (obj.event === 'edit') { //修改入库信息
                            materialsEditModel(goods, data.code, boxId);
                        }
                    });

                    // 接收子页面传来的数据
                    window.configPutGoodsModel = function (model) {
                        if(addWorkGoodsList.length > 0) {
                            addWorkGoodsList.forEach((item, index) => {
                                if(item.packLabelCode === model.packLabelCode) {
                                    addWorkGoodsList[index] = model
                                } else {
                                    addWorkGoodsList.push(model);
                                }
                            })
                        } else {
                            addWorkGoodsList.push(model);
                        }
                        $("input[name='detailWorkBinCode']").val('');
                        table.reload('addWorkGoodsTable', {
                            data: addWorkGoodsList,
                        })
                    }

                    // 表单提交
                    form.on('submit(addPutMaterialsFromSubmit)', function (d) {
                        if(addWorkGoodsList.length === 0) {
                            layer.msg('入库数量不能为空', { icon: 2 });
                            return false;
                        }
                        layer.load(2);
                        admin.req('enterprisecab/order/admin/orderDeliverySignStorage/inventoryInSubmit', JSON.stringify(addWorkGoodsList), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                layer.close(addPutMaterialsOpen);
                                table.reload('trayStoreGoodsListTable')
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        },'POST', true, 'application/json; charset=utf-8');
                        return false;
                    });
                }
            });
        }

        // 添加/修改入库信息
        function materialsEditModel(data, boxCode, boxId) {
            var insTb3A = admin.open({
                type: 1,
                area: '1160px',
                offset: '56px',
                title: '添加入库信息',
                content: $('#materialsAddPutFrom').html(),
                success: function () {
                    let username = config.getUser().username;
                    $(".skuPic").attr("src", data.skuPic);
                    form.val('materialsAddPutFrom', data);
                    $("input[name='quantity']").val(data.packLabelQuantity);
                    $("input[name='storagePeople']").val(username);
                    $("input[name='boxCode']").val(boxCode);
                    $("input[name='storageTime']").val(dateTime(new Date()));

                    // 表单提交
                    form.on('submit(auditFormSubmit)', function (d) {
                        let field = d.field;
                        if(field.quantity == '') {
                            layer.msg('入库数量不能为空', { icon: 2 });
                            return false;
                        }
                        if(parseInt(field.quantity) > parseInt(field.packLabelQuantity)) {
                            layer.msg('入库数量不能大于签收数量', { icon: 2 });
                            return false;
                        }
                        let labelGoods = data;
                        labelGoods.storagePeople = field.storagePeople;
                        labelGoods.quantity = field.quantity;
                        labelGoods.storageTime = field.storageTime;
                        labelGoods.boxId = boxId;
                        labelGoods.remark = field.remark;
                        // 调用父页面方法
                        parent.configPutGoodsModel(labelGoods);
                        layer.close(insTb3A);
                        return false;
                    });

                }
            });
        }

        // 获取当前时间
        const dateTime = (date) => {
            let Y = date.getFullYear(),
                M = date.getMonth() + 1,
                D = date.getDate(),
                H = date.getHours(),
                S = date.getMinutes();
            if (M < 10) {
                M = '0' + M;
            }
            if (D < 10) {
                D = '0' + D;
            }
            if (H < 10) {
                H = '0' + H;
            }
            if (S < 10) {
                S = '0' + S;
            }
            return `${Y}-${M}-${D} ${H}:${S}:00`
        }

    });
</script>